home *** CD-ROM | disk | FTP | other *** search
- /*
- * SFcolours - Star Fighter 3000 colours editor
- * Colours file creation dbox
- * Copyright (C) 2001 Chris Bazley
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public Licence as published by
- * the Free Software Foundation; either version 2 of the Licence, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public Licence for more details.
- *
- * You should have received a copy of the GNU General Public Licence
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- /* ANSI library files */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- /* RISC OS library files */
- #include "wimp.h"
- #include "toolbox.h"
- #include "event.h"
- #include "wimplib.h"
- #include "window.h"
- #include "gadgets.h"
- #include "flex.h"
-
- /* My library files */
- #include "err.h"
- #include "msgtrans.h"
- #include "Macros.h"
- #include "NoBudge.h"
- #include "InputFocus.h"
-
- /* Local headers */
- #include "EditColmap.h"
- #include "Utils.h"
- #include "SFCCreateFile.h"
-
- /* Gadget Ids */
- #define CREATEFILE_MAKECOLS 0x00
- #define CREATEFILE_MAKEHILL 0x01
- #define CREATEFILE_CANCEL 0x02
- #define CREATEFILE_CREATE 0x03
-
- ObjectId CreateFile_sharedid = NULL_ObjectId;
- static int radiosel;
-
- /* ----------------------------------------------------------------------- */
- /* Function prototypes */
-
- static ToolboxEventHandler _CreateFile_clickhandler;
-
- /* ----------------------------------------------------------------------- */
- /* Public functions */
-
- void CreateFile_initialise(ObjectId id)
- {
- /* Record ID */
- CreateFile_sharedid = id;
-
- /* Register event handlers */
- EF(event_register_toolbox_handler(id, ActionButton_Selected, _CreateFile_clickhandler, NULL));
- EF(event_register_toolbox_handler(id, Window_AboutToBeShown, InputFocus_recordcaretpos, NULL));
-
- /* Store initial state of dbox */
- EF(radiobutton_get_state(0, id, CREATEFILE_MAKECOLS, NULL, &radiosel));
- }
-
- /* ----------------------------------------------------------------------- */
- /* Private functions */
-
- static int _CreateFile_clickhandler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
- {
- switch(id_block->self_component) {
-
- case CREATEFILE_CREATE: {
- void *new_cols;
- E_RETV(radiobutton_get_state(0, id_block->self_id, CREATEFILE_MAKECOLS, NULL, &radiosel), 1);
-
- switch(radiosel) {
- case CREATEFILE_MAKECOLS:
- /* Create a new colours file */
- if(!flex_alloc((flex_ptr)&new_cols, sizeof(SF_ColourMap)))
- MG_RETV("NoMem", 1); /* claim event */
- nobudge_register(256);
- memset(new_cols, 0, sizeof(SF_ColourMap));
- nobudge_deregister();
-
- /* Initialise static colours */
- for(int staticcol = 0; staticcol < 256; staticcol++)
- ((SF_ColourMap *)new_cols)->areas.static_colours[staticcol] = staticcol;
- break;
-
- case CREATEFILE_MAKEHILL:
- /* Create a new hill colours file */
- if(!flex_alloc((flex_ptr)&new_cols, sizeof(SF_HillCols)))
- MG_RETV("NoMem", 1); /* claim event */
- nobudge_register(256);
- memset(new_cols, 0, sizeof(SF_HillCols));
- nobudge_deregister();
- break;
- }
-
- ObjectId editing_win = EditColmap_create((flex_ptr)&new_cols, (radiosel == CREATEFILE_MAKEHILL), "<untitled>", 0);
- if(editing_win == NULL)
- flex_free((flex_ptr)&new_cols);
- else
- RE(toolbox_show_object(0, editing_win, Toolbox_ShowObject_Centre, NULL, id_block->self_id, NULL_ComponentId))
-
- } return 1; /* claim event */
-
- case CREATEFILE_CANCEL:
- /* Reset dbox state */
- RE(radiobutton_set_state(0, id_block->self_id, radiosel, 1))
- return 1; /* claim event */
-
- default:
- return 0; /* unknown button */
- }
- }
-